{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 本节课最终成果体验 - 开心一笑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import bs4\n",
    "import time\n",
    "\n",
    "from requests.api import head\n",
    "base = 'http://xiaohua.zol.com.cn'\n",
    "\n",
    "resource = '/detail1/1.html'\n",
    "for i in range(1, 11):\n",
    "    print('')\n",
    "    url = base + resource\n",
    "    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}\n",
    "    html = requests.get(url, headers=headers).text\n",
    "    parser = bs4.BeautifulSoup(html, 'lxml')\n",
    "    try:\n",
    "        joke = parser.select('div.article-text')[0].getText().strip()\n",
    "        print(f'=========第{i}个笑话=========')\n",
    "        print(joke)\n",
    "        next = parser.select('a.next')[0]['href']\n",
    "        resource = next\n",
    "    except:\n",
    "        print('error, sleeep a while')\n",
    "        time.sleep(3)\n",
    "    print()\n",
    "    print('歇会儿再去爬下一个...')\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. 跟着老师开发爬虫"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
